import { useUserStore } from "@/stores/user";
import type { Directive, DirectiveBinding } from "vue";


// 超级管理员
const adminPerms = '*:*:*'

const setAuth = (el: HTMLElement, binding: DirectiveBinding<string>) => {
  // 获取当前用户的权限列表
  const store = useUserStore()
  const perms = store.profile.permissions
  // 超级管理员不做处理
  if (perms.includes(adminPerms)) {
    return
  }
  // 不再用户的权限列表中，就移除节点
  if (!perms.includes(binding.value)) {
    el.remove()
  }
}

// v-auth="权限点"
export const auth: Directive = {
  mounted: setAuth,
  updated: setAuth
}